package org.lejos.example;

// TouchsensorEx1.java
// When wall is hit, backward/turn/forward

import gin.and.tonic.*;

public class TouchsensorEx1 implements TouchListener
{
  private Gear gear;

  public TouchsensorEx1()
  {
    NxtRobot robot = new NxtRobot(true);

    TouchSensor ts = new TouchSensor(gin.and.tonic.SensorPort.S2);
    robot.addPart(ts);
    ts.addTouchListener(this);

    gear = new Gear(gin.and.tonic.MotorPort.B,gin.and.tonic.MotorPort.C);
    gear.setSpeed(50);
    robot.addPart(gear);
    gear.forward();

    Tools.waitEnter("ENTER to quit");
    robot.exit();
  }

  public void pressed(SensorPort port)
  {
    gear.backward(500);
    gear.left(500);
    gear.forward();
  }

  public void released(SensorPort port)
  {
  }

  public static void main(String[] args)
  {
    new TouchsensorEx1();
  }
}